package com.atguigu.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 孙志鹏
 * @createDate 2022/3/31 22:50
 */
@Configuration
public class GateWayConfig {

    /**
     * 自定义GateWay映射
     * @param routeLocatorBuilder
     * @return
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        // 路由器
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        // 当访问/guonei这个地址时，路由会转发到，百度新闻
        routes.route("path_route_atguigu",r -> r.path("/guonei")
                .uri("http://news.baidu.com/guonei")).build();
        return routes.build();
    }
}
